package com.jt.controller;


import com.jt.pojo.Item;
import com.jt.pojo.ItemDesc;
import com.jt.vo.EasyUITable;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.jt.service.ItemService;


@RestController
@RequestMapping("/item")
public class ItemController {

    @Autowired
    private ItemService itemService;
    /**
     * 分页
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping("/query")
    public EasyUITable findPageByRows(int page, int rows) {

        return itemService.findItemByPage(page, rows);
    }

    /**
     * /item/save
     * 新增保存
     */
    @RequestMapping("/save")
    public SysResult saveItem(Item item, ItemDesc itemDesc) {
        itemService.saveItem(item, itemDesc);
        return SysResult.success();
    }

    /**
     * /item/update
     * 商品的修改
     */

    @RequestMapping("/update")
    public SysResult updateItem(Item item, ItemDesc itemDesc) {
        itemService.updateItem(item, itemDesc);
        return SysResult.success();
    }

    /**
     * /item/delete
     * 删除
     */
    @RequestMapping("/delete")
    public SysResult deleteItem(Long... ids) {
        itemService.deleteItem(ids);
        return SysResult.success();
    }

    /**
     * /item/updateStatus/2
     * 上下架
     */
    @PostMapping("/updateStatus/{status}")
    public SysResult updateStatus(@PathVariable Integer status, Long... ids) {
        itemService.updateStatus(ids, status);
        return SysResult.success();
    }

    /**
     * 编辑商品时显示商品描述
     * //item/query/item/desc
     * @param itemId
     * @return
     */
    @RequestMapping("/query/item/desc/{itemId}")
    public SysResult findItemDescById(@PathVariable Long itemId) {
        ItemDesc itemDesc = itemService.findItemDescById(itemId);
        return SysResult.success(itemDesc);
    }


}
